package saeildamil.ch18.communication;

import javax.swing.JOptionPane;

public class PrintThread extends Thread {
	SharedArea sharedArea;

	public PrintThread(SharedArea sharedArea) {
		this.sharedArea = sharedArea;
	}
	
	@Override
	public void run() {
		if(sharedArea.isReady != true){ //PI가 나오지 않았다면
			synchronized(sharedArea){
				try {
					JOptionPane.showMessageDialog(null, "대기");
					sharedArea.wait(); //notify()가 올때까지 대기
				} catch (InterruptedException e) {
					System.out.println(e.getMessage());
				}
			}
		}//end of if
	
		JOptionPane.showMessageDialog(null, "Pi 결과" + sharedArea.result);
	
	}
	
}
